home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * Copyright (C) 1991, Silicon Graphics, Inc.
- * All Rights Reserved.
- */
- /*
- * Define textures used in keyboard display
- *
- * Routines:
- * def_tex ()
- * file_to_tex (fname, tex_id)
- *
- * Jim Bennett
- * 1991
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <gl/image.h>
- #include <gl/gl.h>
- #include "paths.h"
- #include "globj.h"
-
- int valid_texture;
-
- #define NTEV 2
- float decal_tev [NTEV] = { TV_DECAL, TV_NULL };
-
- #define IMAGE_NAME "logo.rgb"
-
- /*
- * def_tex - Define keyboard textures
- */
-
- def_tex ()
-
- {
-
- /* If texture mapping not supported, punt on this. */
-
- valid_texture = FALSE;
- if (!getgdesc (GD_TEXTURE)) return;
-
- /* Load the two textures, and define the texture environment */
-
- if (!file_to_tex ("logo.rgb", LOGO_TEX))
- return;
- if (!file_to_tex ("title.rgb", TITLE_TEX))
- return;
-
- /* All OK, set the texture valid flag and exit */
-
- tevdef (DECAL_ENV, NTEV, decal_tev);
- valid_texture = TRUE;
- }
-
- /*
- * file_to_tex - Convert image file to texture
- *
- * Returns TRUE if conversion succeeded
- */
-
- file_to_tex (fname, tex_id)
-
- char *fname;
- int tex_id;
-
- {
- IMAGE *ifile;
- char *namebuf, *path;
- int width, height, depth;
- unsigned long *teximage;
- short *buf;
- int i, j, k;
- unsigned char *txp;
- int luminance;
-
- /* Make sure a valid texture image is available. */
-
- if (!(path = getenv("SYNTHIA_IMAGE_PATH")))
- path = IMAGE_PATH;
- namebuf = (char *)malloc (strlen(fname) + strlen(path) + 2);
- strcpy (namebuf, path);
- strcat (namebuf, "/");
- strcat (namebuf, fname);
- ifile = iopen (namebuf, "r");
- if (ifile == NULL) return (FALSE);
-
- /* Get the size of the image, and allocate a texture buffer for it */
-
- width = ifile->xsize;
- height = ifile->ysize;
- depth = ifile->dim;
-
- if (depth != 3) return (FALSE); /* RGB file required. */
-
- teximage = (unsigned long *)malloc (height * width * sizeof (long));
- if (teximage == NULL) return (FALSE);
-
- bzero (teximage, height * width * sizeof (long));
-
- /* Read the image into the texture buffer */
-
- buf = (short *)malloc (width * sizeof (short));
- if (buf == NULL) return (FALSE);
-
- for (i=0; i<height; i++)
- {
- for (j=0; j<depth; j++)
- {
- txp = (unsigned char *)teximage +
- (i * (width * sizeof (long))) +
- (depth - j);
- getrow (ifile, buf, i, j);
- for (k=0; k<width; k++, txp += 4)
- *txp = buf[k];
- }
-
- /* Fill in the alpha channel = 1.0 where image is above zero */
-
- txp = (unsigned char *)teximage + (i * (width * sizeof (long)));
- for (k=0; k<width; k++, txp += 4)
- {
- luminance = *(txp+1) + *(txp+2) + *(txp+3);
- if (luminance > 25)
- *txp = 255;
- }
- }
-
- /* Finally, define the texture and the texture environment */
-
- texdef2d (tex_id, 4, width, height, teximage, 0, NULL);
-
- free (buf);
- free (teximage);
- iclose (ifile);
- free (namebuf);
-
- return (TRUE);
- }
-